<!-- 在线客服插件  客服弹窗 -->
<template>
  <div id="yz_service">
    <van-popup v-model="show" position="center" round @click-overlay="close">
        <div class="pop-content">
          <div class="pop-top">
            <div class="left" v-if="url">
              <div class="wrap">
                <span @click.stop="clickChat(url)">
                  <div class="image"><img src="@/assets/images/kf_online_contect@2x.png" /></div>
                </span>
                <div>在线联系</div>
              </div>
            </div>
            <div style="display: flex; align-items: center;" v-if="url && mobile">
              <div class="line"></div>
            </div>
            <div class="right" v-if="mobile">
              <div class="wrap">
                <div class="image">
                  <a :href="`tel:${mobile}`"><img src="@/assets/images/kf_tel_contect@2x.png"/></a>
                </div>
                <div style="margin-top: 0.5rem;">{{ mobile }}</div>
              </div>
            </div>
          </div>
          <div class="pop-bottom" v-if="qr">
            <div class="image">
              <img :src="qr" style="width: 100%; height: 100%;" />
            </div>
          </div>
          <i class="iconfont icon-close11" @click="close"></i>
        </div>
      </van-popup>
  </div>
</template>

<script>
export default {
  props: {
    url: {
      type: String,
      default: ''
    },
    mobile: {
      type: String,
      default: ''
    },
    value: {
      type: Boolean
    },
    qr: {
      type: String,
      default: ''
    },
    order_id:{
      type:null,
      default:''
    },
    orderType:{
      type:null,
      default:''
    }
  },
  watch: {
    value(val) {
      this.show = val;
    }
  },
  data () {
    return {
      show: this.value
    };
  },
  components: {},
  computed: {},
  methods: {
    close() {
      this.show = false;
      this.$emit('input', false);

    },
    checkDomain(inputString) {
      var pattern = /\bwork\.weixin\.qq\.com\b/;
      if (pattern.test(inputString)) {
        return true;
      } else {
        return false;
      }
    },
    clickChat(url) {
      let _url = this.Selecturl(url);
      if (this.fun.isCPS()) {
        if (this.fun.isIosOrAndroid() === "ios") {
          //
        } else {
          try {
            serviceClick();
            window.open(_url,'_blank');
            return;
          } catch (error) {
            window.location.href = _url;
            return;
          }
        }
      }
      window.location.href = _url;
    },
    Selecturl(val){
      if(val.startsWith('tel:')){
        return val;
      }
      if(this.checkDomain(val)){
        // 如果是设置的微信公众号客服链接不携带参数
        return val
      }
      if(this.order_id){
        val += '&order_id='+this.order_id
      }
      if(this.orderType){
        val += '&orderType='+this.orderType
      }
      return val
    }
  }
};

</script>
<style lang='scss' rel='stylesheet/scss' scoped>
.pop-content {
  width: 20rem;
  padding: 3.1875rem 0;
  text-align: center;
  border-radius: 1.1875rem;
  background: #fff;

  .pop-top {
    display: flex;
    align-items: unset;
    justify-content: center;

    .left {
      width: 50%;
      display: flex;
      justify-content: center;

      .wrap {
        display: flex;
        flex-direction: column;
        align-items: center;

        .image {
          width: 2.625rem;
          height: 2.625rem;
          margin-bottom: 0.5rem;

          img {
            width: 100%;
            height: 100%;
          }
        }
      }
    }

    .line {
      width: 1px;
      height: 1.625rem;
      background-color: #999;
    }

    .right {
      width: 50%;
      display: flex;
      justify-content: center;

      .wrap {
        display: flex;
        flex-direction: column;
        align-items: center;

        .image {
          width: 2.625rem;
          height: 2.625rem;
          margin-bottom: 0.5rem;

          img {
            width: 100%;
            height: 100%;
          }
        }
      }
    }
  }

  .pop-bottom {
    margin-top: 1rem;
    width: 100%;
    display: flex;
    justify-content: center;

    .image {
      width: 50%;

      img {
        width: 100%;
        height: 100%;
      }
    }
  }

  .icon-close11 {
    position: absolute;
    right: 1rem;
    top: 1rem;
    font-size: 18px;
  }
}
</style>